import testPanel from './guide.vue'
import testToast from './toast.vue'
import productCheckResult from './productCheckResult.vue'
let guide = {}
guide.install = function (Vue, options) {
  Vue.component(testPanel.name, testPanel)
  Vue.component(testToast.name, testToast)
  const productCheckResultInstance = Vue.extend(testToast)
  let productCheckResultInit;
  const initInstance = () => {
    // 实例化vue实例
    productCheckResultInit = new productCheckResultInstance();
    let productCheckResultEl = productCheckResultInit.$mount().$el;
    document.body.appendChild(productCheckResultEl);
  };
  Vue.prototype.$Dialog = {
    toastPlugin(el) {
      if (isElement(el)) {
        if (!productCheckResultInit) {
          initInstance();
        }
        productCheckResultInit.toastPlugin(el)
      } else {
        console.log("未检测到组件");
      }
    }
  }
}

function isElement(obj) {
  return (typeof HTMLElement === 'object')
    ? (obj instanceof HTMLElement)
    : !!(obj && typeof obj === 'object' && (obj.nodeType === 1 || obj.nodeType === 9) && typeof obj.nodeName === 'string');
}

export default guide